package com.yunkeji.common.enums;

import com.yunkeji.common.exception.AppServiceException;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author 老张
 */
@Getter
@AllArgsConstructor
public enum FileTypeEnum {
    其他(-1, "evn/" + "others"),
    语音(1, "evn/" + "user/" + "uid" + "/voice"),
    相册(2, "evn/" + "user/" + "uid" + "/album"),
    视频(3, "evn/" + "user/" + "uid" + "/video"),
    头像(4, "evn/" + "user/" + "uid" + "/profile"),
    礼物静态图(5, "evn/" + "gift/static"),
    礼物动态图(6, "evn/" + "gift/svga"),
    系统默认(7, "evn/" + "sys"),
    安全中心(8, "evn/" + "sys/help"),
    实名认证(9, "evn/" + "user/" + "uid" + "/auth/real"),
    真人认证(10, "evn/" + "user/" + "uid" + "/auth/video"),
    朋友圈(11, "evn/" + "moment/" + "uid"),
    举报反馈(12, "evn/" + "feedback"),
    安卓安装包(13, "evn/" + "version/android"),
    IOS安装包(14, "evn/" + "version/ios"),
    视频封面动图(15, "evn/" + "user/" + "uid" + "/gif"),
    通话质检(16, "evn/" + "/videosnap" + "uid"),
    安装包(17, "evn/" + "install"),
    BANNER图(18, "evn/" + "banner");

    private Integer code;
    private String basePath;

    public static String getPathByCode(Integer code) {
        FileTypeEnum[] values = FileTypeEnum.values();
        Optional<FileTypeEnum> first =
                Arrays.stream(values).filter(item -> item.getCode() == code).findFirst();
        if (first.isPresent()) {
            return first.get().getBasePath();
        } else {
            throw AppServiceException.paramException("路径未知");
        }
    }
}
